package com.theme.passport.controller.theme;

import com.theme.common.mvc.utils.PageUtils;
import com.theme.common.mvc.view.R;
import com.theme.passport.entity.theme.WidgeTypeAttributeEntity;
import com.theme.passport.service.theme.WidgeTypeAttributeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;



/**
 * 组件类型属性表
 *
 * @author live
 * @email 870459550@qq.com
 * @date 2024-07-14 21:39:08
 */
@RestController
@RequestMapping("widge-type/attribute")
public class WidgeTypeAttributeController {
    @Autowired
    private WidgeTypeAttributeService widgeTypeAttributeService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = widgeTypeAttributeService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 根据组件类型查询属性列表
     */
    @RequestMapping("/listByTypeId")
    public R listByTypeId(@RequestParam Map<String, Object> params){
        List<WidgeTypeAttributeEntity> widgeTypeAttributeList = widgeTypeAttributeService.listByTypeId(params);

        return R.ok().put("widgeTypeAttributeList", widgeTypeAttributeList);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		WidgeTypeAttributeEntity widgeTypeAttribute = widgeTypeAttributeService.getById(id);

        return R.ok().put("widgeTypeAttribute", widgeTypeAttribute);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody WidgeTypeAttributeEntity widgeTypeAttribute){
        widgeTypeAttribute.setCreated(new Date());
		widgeTypeAttributeService.save(widgeTypeAttribute);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody WidgeTypeAttributeEntity widgeTypeAttribute){
        widgeTypeAttribute.setUpdated(new Date());
		widgeTypeAttributeService.updateById(widgeTypeAttribute);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		widgeTypeAttributeService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
